package example.projectphone;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;

import example.projectphone.CustomOnItemSelectedListener;
import example.projectphone.MainActivity;
import example.projectphone.R;


public class MainActivity extends Activity {

	private Spinner spinner1, spinner2, spinner3;
	private Button btnSubmit;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        addItemOnSpinner2();
        addItemOnSpinner3();
        addListenerOnButton();
        addListenerOnSpinnerItemSelection();
    }

    //add items into spinner
    public void addItemOnSpinner2(){
    	spinner2 = (Spinner) findViewById(R.id.spinner2);
    	List<String> list = new ArrayList<String>();
    	list.add("Assignment 1");
    	list.add("Assignment 2");
    	list.add("Assignment 3");
    	ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, 
    			android.R.layout.simple_spinner_item, list);
    	dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    	spinner2.setAdapter(dataAdapter);
    }
    
    public void addItemOnSpinner3(){
    	  
    	  spinner3 = (Spinner) findViewById(R.id.spinner3);
    	  List<String> list = new ArrayList<String>();
    	  list.add("Student 1");
    	  list.add("Student 2");
    	  list.add("Student 3");
    	  list.add("Student 4");
      }
    
    public void addListenerOnSpinnerItemSelection(){
    	spinner1 = (Spinner) findViewById(R.id.spinner1);
    	spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
    }
    
    //get selected drop down list values
    public void addListenerOnButton(){
    	spinner1 = (Spinner) findViewById(R.id.spinner1);
    	spinner2 = (Spinner) findViewById(R.id.spinner2);
    	spinner3 = (Spinner) findViewById(R.id.spinner3);
    	btnSubmit = (Button) findViewById(R.id.btnSubmit);
    	
    	btnSubmit.setOnClickListener (new OnClickListener(){
    	
    		@Override
    		public void onClick(View v){
    			
    			Toast.makeText(MainActivity.this,
    					"OnClickListener : " +
    					"\nSpinner 1 : " + String.valueOf(spinner1.getSelectedItem()) +
    					"\nSpinner 2 : " + String.valueOf(spinner2.getSelectedItem()) +
    					"\nSpinner 3 : " + String.valueOf(spinner3.getSelectedItem()),
    						Toast.LENGTH_SHORT).show();
    		}
    	});
    }
}